package com.flute.framework.autoprompt;

import java.util.Arrays;

public class TokenPriority {
	private double[] priorities;

	private TokenPriority() {
		this.priorities = new double[3];
	}

	public static TokenPriority getInstance() {
		return new TokenPriority();
	}

	public void addPriority(Double priority, int pos) {
		this.priorities[pos - 1] = priority;
	}

	@Override
	public int hashCode() {
		assert Boolean.FALSE : "hashCode not designed";
		return 42; // any arbitrary constant will do
	}

	public boolean higherThan(TokenPriority priority) {
		for (int i = 0; i < priorities.length; i++) {
			if (priorities[i] > priority.priorities[i]) {
				return Boolean.TRUE;
			} else if (priorities[i] < priority.priorities[i]) {
				return Boolean.FALSE;
			}
		}
		return Boolean.TRUE;
	}

	public double[] getPriority() {
		return priorities;
	}

	public String getPriorityString() {
		StringBuffer sb = new StringBuffer();
		for (double p : priorities) {
			sb.append(p + " ");
		}

		return sb.toString().trim();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return Boolean.TRUE;
		if (obj == null)
			return Boolean.FALSE;
		if (!(obj instanceof TokenPriority))
			return Boolean.FALSE;
		TokenPriority other = (TokenPriority) obj;
		if (!Arrays.equals(priorities, other.priorities))
			return Boolean.FALSE;
		return Boolean.TRUE;
	}
}
